import java.net.*;
import java.io.*;



public class FileServer {
  public static void main (String [] args ) throws IOException {
	  
    // create socket
    ServerSocket servsock = new ServerSocket(13267);
    while (true) {
      System.out.println("Waiting...");

      Socket sock = servsock.accept();
      System.out.println("Accepted connection : " + sock);

      // sendfile
      

      File myFile = new File ("woot.mp3"); // Get file
      byte [] mybytearray  = new byte [(int)myFile.length()]; // Create byte array
      FileInputStream fis = new FileInputStream(myFile); // Create file input stream
      

      
      BufferedInputStream bis = new BufferedInputStream(fis); // Create buffer input stream from file input stream
      bis.read(mybytearray,0,mybytearray.length);  // read bytes in from stream to array
      
      ObjectOutputStream os = new ObjectOutputStream(sock.getOutputStream());  //create output stream
      System.out.println("Sending...");
      data myDataObject = new data(mybytearray);
      os.writeObject(myDataObject);
      //os.write(mybytearray,0,mybytearray.length);
      os.flush();   //clear buffer
      sock.close();  // close socket
    }
    }
}
